package ae.pcfc.cldos.online.web.controller.client.company.nocandletters;


import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import ae.pcfc.cldos.online.common.ConstantsCommon;
import ae.pcfc.cldos.online.common.exception.BadAppException;
import ae.pcfc.cldos.online.common.vo.nandl.NocLetterVO;
import ae.pcfc.cldos.online.web.ViewPath;
import ae.pcfc.cldos.online.web.model.NocAndLettersModel;

/**
 * 
 * @author Asna
 *
 */
@Controller
@RequestMapping(ViewPath.__NOC_LETTERS_VIEW)
public class NocAndLettersViewController extends NocAndLettersCommonController {
	
	private static final String NOC_AND_LETTERS_PATH = "client.company.nocandletters.view.form";
	
	
	@ModelAttribute
	public void populateBreadCrumbs(ModelMap model, @RequestParam String appId) {
		breadCrumbsFactoryService.populateallAppReqDtlBreadCrumb(model);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/form.htm")
	public ModelAndView form( HttpServletRequest request,
			ModelMap model,
			@RequestParam String appId,			
			@ModelAttribute(value="nocAndLettersModel") NocAndLettersModel nocAndLettersModel,
			BindingResult errors) throws BadAppException {
		
		NocLetterVO nocLetterVO = getNocLetterDelegate().getNocLetterAppInfo(encryptionDelegate.decodeAndDecrypt(appId), getUserVO(), ConstantsCommon.Steps.ALL_APP_REQUEST);
		getMapper().map(nocLetterVO.getNocLetterDetailsVO(),nocAndLettersModel);
		nocAndLettersModel.setWfStatus(nocLetterVO.getWfStatus());
		
		model.put("appId", appId);
		model.put("nocAndLettersModel",nocAndLettersModel);
		model.put("comments", nocLetterVO.getApplicationCommentVOs());		
		
		return new ModelAndView(NOC_AND_LETTERS_PATH,model);
	}
	



}
